package com.example.demo.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import javax.annotation.Resource;

/**
 * @ClassName RedissonConfig
 * @Description
 * @Author 51
 * @Date 2020年3月17日 下午2:03:34
 */
@Configuration
public class RedissonConfig {

	@Resource
	private Environment environment;

	@Bean
	RedissonClient redisson() {
		String url = environment.getProperty("spring.redis.host");
		String port = environment.getProperty("spring.redis.port");
		String redisUrl = String.format("redis://%s:%s", url, port);
		System.out.println("redis加载配置");

		Config config = new Config();
		config.useSingleServer().setAddress(redisUrl);
		return Redisson.create(config);

	}
}
